﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddCrmCustomerChannel.aspx.cs" Inherits="ZX.WebApp.Crm.Customer.AddCrmCustomerChannel" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/paginator/paginator-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/resize/resize-min.js"></script>
    <script src="../../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.json-2.2.js" type="text/javascript"></script>
    <script src="../../Scripts/Jquery.form.js" type="text/javascript"></script>
    <script src="../../Scripts/inputDate.js" type="text/javascript"></script>
    <script src="../../Scripts/extend.validate.js" type="text/javascript"></script>
    <script src="../../Scripts/Public.js" type="text/javascript"></script>
    <script src="../../Scripts/CombinButton.js" type="text/javascript"></script>
    <link href="../../Styles/extendTable.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/base.css" rel="stylesheet" type="text/css" />
</head>
<body class="yui-skin-sam" onkeydown="PreventBSK()">
    <form id="form1" runat="server">
    <div id="toolbar" style="margin-top: 12px; text-align: center;">
        <button type="button" id="btnCheck" name="btnCheck">
            检查</button>&nbsp;&nbsp;
        <button type="button" id="btnSave" name="btnSave">
            保存</button>&nbsp;&nbsp;
        <button type="button" id="btnBack" name="btnBack">
            退回</button>&nbsp;&nbsp;
        <button type="button" id="btnClose" name="btnClose">
            取消</button>
    </div>
    <div class="fieldForm" id="fieldForm">
        <div id="content">
            <h3>客户基本信息</h3>
            <table class="table1">
                <tr>
                    <th width="14%">
                        <span style="color: Red">*</span><span>客户编码</span>
                    </th>
                    <td width="36%">
                        <input runat="server" type="text" id="Code" name="Code" readonly="readonly" class="width35"
                            style="background-color: #e7eaf4;" />
                    </td>
                    <th width="14%">
                        <span>信息专员</span>
                    </th>
                    <td width="36%">
                        <span style='color: #FF0000'>
                            <input runat="server" type="text" id="txtAddUserId" name="txtAddUserId" readonly="readonly"
                                class="width35" style="background-color: #e7eaf4;" />
                            <input type="hidden" runat="server" id="hiddenAddUser" name="hiddenAddUser" />
                            <input type="hidden" runat="server" id="AddTime" name="AddTime" />
                            <input type="hidden" runat="server" id="ModifyUser" name="ModifyUser" />
                            <input type="hidden" runat="server" id="ModifyTime" name="ModifyTime" />
                        </span>
                    </td>
                </tr>
                <tr>
                    <th>
                        <span style="color: Red">*</span><span>客户名称</span>
                    </th>
                    <td colspan="3">
                        <input runat="server" type="text" id="CustomerName" name="CustomerName" onkeydown="showSetNum('CustomerName','ShowCustoemrName',50)"
                            onkeyup="showSetNum('CustomerName','ShowCustoemrName',50)" onblur="ValidateCustomerName(this.value,'客户名称','CustomerName','ShowCustoemrName');"
                            class="width30" />
                        <span class="span_font">(0-50字)请填写完整公司全称</span> <span class="span_font" id="ShowCustoemrName">
                        </span>
                    </td>
                </tr>
                <tr>
                    <th>
                        <span style="color: Red">*</span><span>公司地址</span>
                    </th>
                    <td colspan="3">
                        <asp:DropDownList ID="State" name="State" runat="server" AppendDataBoundItems="true">
                            <asp:ListItem Value="中国">中国</asp:ListItem>
                        </asp:DropDownList>
                        <asp:DropDownList ID="Province" name="Province" runat="server" AppendDataBoundItems="true">
                            <asp:ListItem Value=" ">选择省份</asp:ListItem>
                        </asp:DropDownList>
                        <asp:DropDownList ID="City" name="City" runat="server" AppendDataBoundItems="true">
                            <asp:ListItem Value=" ">选择城市</asp:ListItem>
                        </asp:DropDownList>
                        <asp:DropDownList ID="Area" name="Area" runat="server" AppendDataBoundItems="true">
                            <asp:ListItem Value=" ">选择区县</asp:ListItem>
                        </asp:DropDownList>
                        <input runat="server" type="text" id="Address" name="Address" onkeydown="showSetNum('Address','ShowAddress',100)"
                            onkeyup="showSetNum('Address','ShowAddress',100)" onblur="showSetNull('ShowAddress')"
                            style="width: 21%;" />
                        <span class="span_font" id="ShowAddress"></span>
                    </td>
                </tr>
                <tr>
                    <th>
                        <span style="color: Red">*</span><span>决策人姓名</span>
                    </th>
                    <td>
                        <input runat="server" type="text" id="Decisionmaker" onblur="IsChinese(this.value,'决策人','Decisionmaker')"
                            size="30" maxlength="30" name="Decisionmaker" class="width35" />
                    </td>
                    <th>
                        <span style="color: Red">*</span><span>决策人性别</span>
                    </th>
                    <td>
                        <asp:DropDownList ID="DecisionSex" name="DecisionSex" runat="server" class="width38">
                            <asp:ListItem Value=""> </asp:ListItem>
                            <asp:ListItem Value="M">男</asp:ListItem>
                            <asp:ListItem Value="F">女</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <th>
                        <span style="color: Red">*</span><span>决策人手机1</span>
                    </th>
                    <td>
                        <input type="text" runat="server" id="DecisionTel" name="DecisionTel" onkeypress="return(event.keyCode>47&&event.keyCode<58)"
                            onpaste="return !clipboardData.getData('text').match(/\D/)" maxlength="20" class="width35" />
                        <input type="hidden" id="hiddenDecisionTel" runat="server" />
                    </td>
                    <th>
                        <span>决策人手机2</span>
                    </th>
                    <td>
                        <input type="text" runat="server" id="DecisionTel2" name="DecisionTel2" onkeypress="return(event.keyCode>47&&event.keyCode<58)"
                            onpaste="return !clipboardData.getData('text').match(/\D/)" maxlength="20" class="width35" />
                        <input type="hidden" id="hiddenDecisionTel2" runat="server" />
                    </td>
                </tr>
                <tr>
                    <th>
                        <span style="color: Red">*</span><span>决策人职位</span>
                    </th>
                    <td>
                        <input runat="server" type="text" id="DecisionPosition" onblur="IsChinese(this.value,'决策人职务','DecisionPosition')"
                            size="20" maxlength="20" name="DecisionPosition" class="width35" />
                    </td>
                    <th>
                        <span style="color: Red">*</span><span>公司电话1</span>
                    </th>
                    <td>
                        <input type="text" runat="server" id="Tel1" name="Tel1" onblur="IsTel(this.value,'公司电话1','Tel1')"
                            class="width35" />
                        <span class="span_font">格式:0755-12345678</span>
                    </td>
                </tr>
                <tr>
                    <th>
                        <span style="color: Red">*</span><span>主营业务</span>
                    </th>
                    <td>
                        <input runat="server" type="text" id="CompanyProduct" name="CompanyProduct" size="100"
                            maxlength="100" class="width35" />
                    </td>
                    <th>
                        <span>公司电话2</span>
                    </th>
                    <td>
                        <input type="text" runat="server" id="Tel2" name="Tel2" onblur="IsTel(this.value,'公司电话2','Tel2')"
                            class="width35" />
                        <span class="span_font">格式:0755-12345678</span>
                    </td>
                </tr>
            </table>
            <h3>
                公司基本信息</h3>
            <table class="table1">
                <tr>
                    <th width="14%">
                        <span style="color: Red">*</span><span>员工人数</span>
                    </th>
                    <td width="36%">
                        <asp:DropDownList ID="PersonId" runat="server" class="width38" AppendDataBoundItems="true">
                            <asp:ListItem Value=""></asp:ListItem>
                        </asp:DropDownList>
                    </td>
                    <th width="14%">
                        <span style="color: Red">*</span><span>客户区域</span>
                    </th>
                    <td width="36%">
                        <input type="hidden" id="AreaId" name="AreaId" runat="server" />
                        <input type="text" id="txtAreaId" runat="server" name="txtAreaId" readonly="readonly"
                            class="width35" />
                        <button id="btnAreaId" name="10" type="button" runat="server" class="btnCheck" style="height: 25px;">
                            选择</button>
                    </td>
                </tr>
                <tr>
                    <th>
                        <span style="color: Red">*</span><span>客户类型</span>
                    </th>
                    <td>
                        <asp:DropDownList ID="TypeId" runat="server" class="width38">
                        </asp:DropDownList>
                    </td>
                    <th>
                        <span style="color: Red">*</span><span>所属行业</span>
                    </th>
                    <td>
                        <input type="hidden" id="TradeId" name="TradeId" runat="server" />
                        <input type="text" id="txtTradeId" runat="server" name="txtTradeId" readonly="readonly"
                            class="width35" />
                        <button id="btnTradeId" name="11" type="button" runat="server" class="btnCheck" style="height: 25px;">
                            选择</button>
                    </td>
                </tr>
                <tr>
                    <th>
                        <span style="color: Red">*</span><span>公司产值</span>
                    </th>
                    <td>
                        <asp:DropDownList ID="ProductId" runat="server" class="width38" AppendDataBoundItems="true">
                            <asp:ListItem Value=""></asp:ListItem>
                        </asp:DropDownList>
                    </td>
                    <th>
                        <span style="color: Red">*</span><span>客户来源</span>
                    </th>
                    <td>
                        <asp:DropDownList ID="OriginId" runat="server" class="width38" AppendDataBoundItems="true">
                            <asp:ListItem Value=""></asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <th>
                        <span style="color: Red">*</span><span>公司性质</span>
                    </th>
                    <td>
                        <asp:DropDownList ID="PropertyId" runat="server" class="width38" AppendDataBoundItems="true">
                            <asp:ListItem Value=""></asp:ListItem>
                        </asp:DropDownList>
                    </td>
                    <th>
                        <span style="color: Red">*</span><span>客户级别</span>
                    </th>
                    <td>
                        <asp:DropDownList ID="LevelId" runat="server" class="width38" AppendDataBoundItems="true">
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <th>
                        <span>管理中遇到问题</span>
                    </th>
                    <td colspan="3">
                        <textarea runat="server" id="ManagerQuestion" name="ManagerQuestion" onkeydown="showSetNum('ManagerQuestion','ShowManagerQuestion',500)"
                            onkeyup="showSetNum('ManagerQuestion','ShowManagerQuestion',500)" onblur="showSetNull('ShowManagerQuestion')"
                            style="width: 65%; height: 50px;"></textarea>
                        <span class="span_font">(0-500字)</span> <span class="span_font" id="ShowManagerQuestion">
                        </span>
                    </td>
                </tr>
                <tr>
                    <th>
                        <span>未来3-5年战略目标</span>
                    </th>
                    <td colspan="3">
                        <textarea runat="server" id="StrongPoint" name="StrongPoint" onkeydown="showSetNum('StrongPoint','ShowStrongPoint',200)"
                            onkeyup="showSetNum('StrongPoint','ShowStrongPoint',200)" onblur="showSetNull('ShowStrongPoint')"
                            style="width: 65%; height: 50px;"></textarea>
                        <span class="span_font">(0-200字)</span> <span class="span_font" id="ShowStrongPoint">
                        </span>
                    </td>
                </tr>
                <tr>
                    <th>
                        <span>备注</span>
                    </th>
                    <td colspan="3">
                        <textarea runat="server" id="Explain" name="Explain" onkeydown="showSetNum('Explain','ShowExplain',500)"
                            onkeyup="showSetNum('Explain','ShowExplain',500)" onblur="showSetNull('ShowExplain')"
                            style="width: 65%; height: 50px;"></textarea>
                        <span class="span_font">(0-500字)</span> <span class="span_font" id="ShowExplain">
                        </span>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <input type="hidden" id="ID" runat="server" />
    <input type="hidden" id="WorkFlowInsId" runat="server" />
    <input type="hidden" id="WorkTaskInsId" runat="server" />
    <div id="dialog1" class="yui-pe-content">
        <div class="hd">
            客户信息</div>
        <div class="bd">
            <iframe id="EditUIWindow1" frameborder="0" src="" style="width: 100%; height: 100%;
                margin: 0px; padding: 0px;"></iframe>
        </div>
    </div>
    </form>
    <form id="form2" style="display: none" action="../../Extend/AjaxData/DataSave.aspx">
    <textarea style="display: none" id="jsonDataContent" rows="2" cols="2" name="jsonDataContent"></textarea>
    </form>
</body>
<script type="text/javascript">
    var action = "<% =DataAction %>", 
        entity = "<% =EntityName %>",
        userid = "<%=UserID %>", 
        flag = getPar1("flag"),
        vtype = getPar1("type"),
        OperStatus=getPar1("OperStatus"),
        WorkFlowId="",WorkTaskId="",condition = "";
    var getTsid=$("#WorkTaskInsId").val();
    var btnCheck="", btnSave = "",btnBack="", btnClose = "";
    <asp:Literal ID="EditTemplate" runat="server"></asp:Literal>
    (function () {
        //YUI布局
        var Dom = YAHOO.util.Dom,
                Event = YAHOO.util.Event;
        Event.onDOMReady(function () {
            var layout = new YAHOO.widget.Layout({
                units: [
                        { position: 'bottom', height: 50, body: 'toolbar', gutter: '1 1 1 1', scroll: null, zIndex: 2 },
                        { position: 'center', body: 'fieldForm', gutter: '0 1 1 1', scroll: true }
                    ]
            });
            layout.render();
        });

        if(flag==1&&OperStatus!=1){ //流程节点
            $("#btnAreaId").hide();
            $("#btnTradeId").hide();
            var obj = document.getElementById("fieldForm"); //得到DIV对象
            var e = obj.getElementsByTagName("input"); //得到此DIV里的所有INPUT对象
            var s = obj.getElementsByTagName("select");
            var t = obj.getElementsByTagName("textarea");
            for (var i = 0; i < e.length; i++) {
                $("#" + e[i].id + "").attr("readonly", "readonly");
            }
            for (var j = 0; j < s.length; j++) {
                s[j].disabled = true;
            }
            for (var k = 0; k < t.length; k++) {
                $("#" + t[k].id + "").attr("readonly", "readonly");
            }
        }
        if(flag==0){ //新增
            WorkFlowId = getPar1("wfid");
            WorkTaskId = getPar1("wtid");

            $("#TypeId").get(0).selectedIndex = 0;
            $('#TypeId').attr("disabled","true");
            $("#OriginId").get(0).selectedIndex = 6;
            $('#OriginId').attr("disabled","true");
        }else{
            WorkFlowId = getPar1("WorkflowId");
            WorkTaskId = getPar1("WorktaskId");
        }
    })();
    //关闭当前页
    var fnClose = function () {
        window.parent.$("#tabs").tabs('close', '<%=PageTitle %>');
    };


    $(document).ready(function(){
        //决策人手机1只能为数字
        $("#DecisionTel").keypress(function (e) {
            //注意此处不要用keydown方法，否则不能禁用Ctrl+C与Ctrl+V,具体原因请自行查找keyPress与keyDown区分，十分重要，请细查
            if ($.browser.msie) {  //判断浏览器
                if (((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 8)) { //判断键值 
                    return true;
                } else {
                    return false;
                }
            } else {
                if (((e.which > 47) && (e.which < 58)) || (e.which == 8) || (event.keyCode == 17)) {
                    return true;
                } else {
                    return false;
                }
            }
        }).focus(function () {
            this.style.imeMode = 'disabled'; //禁用输入法,禁止输入中文字符
        }).bind("paste", function () {
            //alert($("#text").val());
            //return false;
        }).keyup(function (e) {
            _v = $("#DecisionTel").val();
            for (_i = 0; _i < _v.length; _i++) {
                _c = _v.charAt(_i);
                if (isNaN(_c)) {
                    $("#DecisionTel").val("");
                    return;
                }
            }
        });
        //决策人手机2只能为数字
        $("#DecisionTel2").keypress(function (e) {
            //注意此处不要用keydown方法，否则不能禁用Ctrl+C与Ctrl+V,具体原因请自行查找keyPress与keyDown区分，十分重要，请细查
            if ($.browser.msie) {  //判断浏览器
                if (((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 8)) { //判断键值 
                    return true;
                } else {
                    return false;
                }
            } else {
                if (((e.which > 47) && (e.which < 58)) || (e.which == 8) || (event.keyCode == 17)) {
                    return true;
                } else {
                    return false;
                }
            }
        }).focus(function () {
            this.style.imeMode = 'disabled'; //禁用输入法,禁止输入中文字符
        }).bind("paste", function () {
            //alert($("#text").val());
            //return false;
        }).keyup(function (e) {
            _v = $("#DecisionTel2").val();
            for (_i = 0; _i < _v.length; _i++) {
                _c = _v.charAt(_i);
                if (isNaN(_c)) {
                    $("#DecisionTel2").val("");
                    return;
                }
            }
        });
        //省份下拉绑定
        $('#Province').change(function () {
            var vProvince = $(this).children('option:selected').val();
            if (vProvince != "") {
                document.getElementById("City").options.length = 0;
                document.getElementById("Area").options.length = 0;
                $("#City").append("<option value=''>选择城市</option>");
                $("#Area").append("<option value=''>选择区县</option>");
                var vc = "ProvinceId='" + vProvince + "'";
                YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/JSONList.aspx?type=1&entity=SysCity&customCondition=" + vc + "", //条件 
                            {success: function (res) {
                                try {
                                    var str = res.responseText;
                                    var obj = eval(str);
                                    for (var i = 0; i < obj.length; i++) {
                                        if (obj[i].Code != undefined || obj[i].Name != undefined) {
                                            $("#City").append("<option value='" + obj[i].Code + "'>" + obj[i].Name + "</option>");
                                        }
                                    }
                                }
                                catch (e) {
                                }
                                finally {
                                }
                            }, failure: function () { }
                        });
            }
        });
        //城市下拉绑定
        $('#City').change(function () {
            var vCity = $('#City').children('option:selected').val();
            if (vCity != "") {
                document.getElementById("Area").options.length = 0;
                $("#Area").append("<option value=''>选择区县</option>");
                var vc = "CityId='" + vCity + "'";
                YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/JSONList.aspx?type=1&entity=SysArea&customCondition=" + vc + "", //条件 
                            {success: function (res) {
                                try {
                                    var str = res.responseText;
                                    var obj = eval(str);
                                    for (var i = 0; i < obj.length; i++) {
                                        $("#Area").append($("<option></option>").val(obj[i].Name).html(obj[i].Name));
                                    }
                                }
                                catch (e) {
                                }
                                finally {
                                }
                            }, failure: function () { }
                        });
            }
        });
    });
    YAHOO.example.init = function () {
        function onButtonClick(p_oEvent) {
            switch (this.get("id")) {
                case "btnCheck":
                    CheckCustomerData();
                    break;
                case "btnSave":
                    Save();
                    break;
                case "btnBack":
                    BackData();
                    break;
                case "btnClose":
                    fnClose();
                    break;
                default:
                    break;
            }
        }
        YAHOO.util.Event.onContentReady("toolbar", function () {
            btnCheck = new YAHOO.widget.Button("btnCheck");
            btnCheck.on("click", onButtonClick);
            btnSave = new YAHOO.widget.Button("btnSave");
            btnSave.on("click", onButtonClick);
            btnBack = new YAHOO.widget.Button("btnBack");
            btnBack.on("click", onButtonClick);
            btnClose = new YAHOO.widget.Button("btnClose");
            btnClose.on("click", onButtonClick);
            if(flag==0||OperStatus==1){  //新增
                btnCheck._button.style.display = "none";
                $("#btnCheck").attr('disabled', "true");
                btnBack._button.style.display = "none";
                $("#btnBack").attr('disabled', "true");
            }
        });
    } ();

    
    var _fn, _id;
    function ShowDialog(fn, id, src) {
        _fn = fn;
        _id = id;
        document.getElementById("EditUIWindow1").src = src;
        YAHOO.example.container.dialog1.show();
    }
    YAHOO.namespace("example.container");
    YAHOO.util.Event.onDOMReady(function () {
        var handleSubmit1 = function () {
            var editwindow = document.getElementById("EditUIWindow1");
            if (editwindow) {
                editwindow.contentWindow.ChooseInfo();
            }
            YAHOO.example.container.dialog1.hide();
        };
        var handleCancel = function () {
            this.cancel();
        };
        var handleSuccess = function (o) {
            var response = o.responseText;
            response = response.split("<!")[0];
            document.getElementById("resp").innerHTML = response;
        };
        var handleFailure = function (o) {
            alert("Submission failed: " + o.status);
        };
        YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1",
	    { width: "650px",
	        height: "350px",
	        xy: [10, 10],
	        fixedcenter: true,
	        visible: false,
	        draggable: false,
	        modal: true,
	        close: true,
	        autofillheight: "body",
	        constraintoviewport: true,
	        buttons: [{ text: "确定", handler: handleSubmit1, isDefault: true },
				    { text: "取消", handler: handleCancel}]
	    });
        YAHOO.example.container.dialog1.callback = { success: handleSuccess, failure: handleFailure };
        YAHOO.example.container.dialog1.render();
    });

    var tempData=0;
    //保存数据
    var Save = function () {
        if(setValue()){
            if(flag==1){
                if(OperStatus==1){//退回后保存修改
                    if(confirm("是否确定保存提交?")){
                        trySave(4); //退回后保存修改
                    }
                }else{
                    if(tempData==0){
                        alert("请先检查!");
                        return;
                    }else{
                        if(confirm("是否确定保存提交?")){
                            trySave(2); //检查后保存
                        }
                    }
                }
            }else{
                if(vtype==1){ //点击按钮修改不走流程
                    if(confirm("是否确定保存当前修改信息?")){
                        trySave(5); //按钮修改不走流程
                    }
                }else{
                    if(confirm("是否确定保存?")){
                        trySave(0); //新增保存
                    }
                }
            }
        }
    };
    //检查
    var CheckCustomerData = function(){
        if(setValue()){
            trySave(1);
            tempData=1;
        }
    };
    var BackData = function(){
        if(confirm("是否确定退回?")){
            trySave(3); //退回
        }
    };
    var setValue=function(){
        instance[0].ID = $('#ID').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].Code = $('#Code').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].CustomerName = $('#CustomerName').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].Address = $('#Address').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].State = $("#State").find("option:selected").text();
        instance[0].Province = $("#Province").find("option:selected").text();
        instance[0].City = $("#City").find("option:selected").text();
        instance[0].Area = $("#Area").find("option:selected").text();
        instance[0].Decisionmaker = $('#Decisionmaker').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].DecisionTel = $('#DecisionTel').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].DecisionTel2 = $('#DecisionTel2').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].DecisionPosition = $('#DecisionPosition').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].DecisionSex = $('#DecisionSex').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].CompanyProduct = $('#CompanyProduct').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].Tel1 = $('#Tel1').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].Tel2 = $('#Tel2').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].PersonId = $('#PersonId').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].AreaId = $('#AreaId').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].TypeId = $('#TypeId').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, ""); 
        instance[0].TradeId = $('#TradeId').val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].ProductId = $('#ProductId').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].OriginId = $("#OriginId").val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].PropertyId = $('#PropertyId').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].LevelId = $('#LevelId').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].ManagerQuestion = $('#ManagerQuestion').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].StrongPoint = $('#StrongPoint').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].Explain = $('#Explain').val().replace(/(^\s*)|(\s*$)/g, '').replace(/\s/g, "");
        instance[0].IsHistory = "0";
        instance[0].IsValue = "1";
        instance[0].WorkFlowId = WorkFlowId;
        instance[0].WorkTaskId = WorkTaskId;
        instance[0].WorkFlowInsId = $("#WorkFlowInsId").val();
        instance[0].WorkTaskInsId = $("#WorkTaskInsId").val();
        if (instance[0].CustomerName == "") {
            alert("客户名称不能为空!");
            $('#CustomerName').focus();
            return false;
        }
        if (instance[0].CustomerName.length < 6) {
            alert("客户名的长度不能少于6个字,请输入公司全称!\n如：深圳市中旭企业管理股份有限公司");
            $('#CustomerName').focus();
            return false;
        }
        if (instance[0].Province == "" || instance[0].Province == "选择省份") {
            alert("省份不能为空!");
            $('#Province').focus();
            return false;
        }
        if (instance[0].City == "" || instance[0].City == "选择城市") {
            alert("城市不能为空!");
            $('#City').focus();
            return false;
        }
        if (instance[0].Province == "选择省份") {
            instance[0].Province = "";
        }
        if (instance[0].City == "选择城市") {
            instance[0].City = "";
        }
        if (instance[0].Area == "选择区县") {
            instance[0].Area = "";
        }
        if (instance[0].Address == "") {
            alert("地址不能为空!");
            $('#Address').focus();
            return false;
        }
        if (instance[0].Decisionmaker == "") {
            alert("决策人姓名不能为空!");
            $('#Decisionmaker').focus();
            return false;
        }
        if (instance[0].Decisionmaker.length < 2) {
            alert("决策人姓名不能为单个汉字!");
            $('#Decisionmaker').focus();
            return false;
        }
        if (instance[0].DecisionTel == "") {
            alert("决策人手机不能为空!");
            $('#DecisionTel').focus();
            return false;
        }
        if (instance[0].DecisionPosition == "") {
            alert("决策人职务不能为空!");
            $('#DecisionPosition').focus();
            return false;
        }
        if (instance[0].DecisionSex == "" || instance[0].DecisionSex == null) {
            alert("决策人性别不能为空!");
            $('#DecisionSex').focus();
            return false;
        }
        if (instance[0].CompanyProduct == "") {
            alert("主营业务不能为空!");
            $('#CompanyProduct').focus();
            return false;
        }
        if (instance[0].Tel1 == "") {
            alert("公司电话1不能为空!");
            $('#Tel1').focus();
            return false;
        }
        if (instance[0].PersonId == "" || instance[0].PersonId == null) {
            alert("员工人数不能为空!");
            $('#PersonId').focus();
            return false;
        }
        if (instance[0].AreaId == "" || instance[0].AreaId == null) {
            alert("客户区域不能为空!");
            $('#AreaId').focus();
            return false;
        }
        if (instance[0].TypeId == "" || instance[0].TypeId == null) {
            alert("客户类型不能为空!");
            $('#TypeId').focus();
            return false;
        }
        if (instance[0].TradeId == "" || instance[0].TradeId == null) {
            alert("所属行业不能为空!");
            $('#TradeId').focus();
            return false;
        }
        if (instance[0].ProductId == "" || instance[0].ProductId == null) {
            alert("公司产值不能为空!");
            $('#ProductId').focus();
            return false;
        }
        if (instance[0].OriginId == "" || instance[0].OriginId == null) {
            alert("客户来源不能为空!");
            $('#OriginId').focus();
            return false;
        }
        if (instance[0].PropertyId == "" || instance[0].PropertyId == null) {
            alert("公司性质不能为空!");
            $('#PropertyId').focus();
            return false;
        }
        if (instance[0].LevelId == "" || instance[0].LevelId == null) {
            alert("客户级别不能为空!");
            $('#LevelId').focus();
            return false;
        }
        var json = $.toJSON(instance[0]).replace(/'/g, "[B]");
        $("#jsonDataContent").val(json);
        return true;
    };
    var trySave = function (obj) {
        //debugger
        var formObject = document.getElementById('form2');
        YAHOO.util.Connect.setForm(formObject);
        if(obj==0){ //新增
            var cObj = YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/CustomOperating.aspx?flag=1&t=0&action=" + action + "&entity=" + entity + "", callback);
        }else if(obj==1 || obj==2){  //1:检查 2:提交
            var customerId=$("#ID").val();
            var OperatorInstanceId=getPar1("OperatorInstanceId");
            var cObj = YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/CustomOperating.aspx?flag=1&t="+obj+"&OperatorInstanceId="+OperatorInstanceId+"&action=delete&entity=" + entity + "&id="+customerId+"", callback);
        }else if(obj==3){ //退回
            var WorktaskId=getPar1("WorktaskId");
            var WorktaskInsId=getPar1("WorktaskInsId");
            var WorkflowId=getPar1("WorkflowId");
            var WorkflowInsId=getPar1("WorkflowInsId");
            var OperatorInstanceId=getPar1("OperatorInstanceId");
            var cObj = YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/CustomOperating.aspx?flag=1&action=check&entity=" + entity + "&OperatorInstanceId="+OperatorInstanceId+"&WorkflowId="+WorkflowId+"&WorktaskId="+WorktaskId+"&WorkflowInsId="+WorkflowInsId+"&WorktaskInsId="+WorktaskInsId+"", callback);
        }else if(obj==4){ //退回后重新提交
            var cObj = YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/CustomOperating.aspx?flag=1&t=4&action=" + action + "&entity=" + entity + "", callback);
        }else if(obj==5){ //按钮修改不走流程
            var cObj = YAHOO.util.Connect.asyncRequest('POST', "../../Extend/AjaxData/CustomOperating.aspx?flag=1&t=5&action=" + action + "&entity=" + entity + "", callback);
        }
    };
    var responseSuccess = function (res) {
        try {
            //debugger
            var str = res.responseText;
            if (str == "1") {
                if(vtype!=1){
                    window.location.href = "../../Crm/BasePages/tooltip.aspx?worktaskInstanceId=" + getTsid;
                }else{
                    alert("保存成功!");
                    fnClose();
                }
            } else {
                alert(str);
            }
        } catch (e) {
        }
        finally {
        }
    };
    var responseFailure = function (error) {
        alert("数据错误：" + error.statusText);
    };
    var callback = {
        success: responseSuccess,
        failure: responseFailure
    };
</script>
<script src="../Scripts/appjs/model.<% =EntityName %>.js" type="text/javascript" language="javascript"></script>
</html>
